package 作业;

/**
 * Created with IntelliJ IDEA.
 * Description:将count和increase方法都定义为了类方法
 * User: lenovo
 * Date: 2022-09-24
 * Time: 22:26
 */
public class Demo1 {
public static int count = 0;//定义count为类成员变量
public static synchronized void increase(){
    count++;
}
    public static void main(String[] args) throws InterruptedException {
        //Counter counter = new Counter();
        Thread t1 = new Thread(()->{
            for (int i = 0; i<10000;i++){
                increase();
            }
        },"这是线程1");

        Thread t2 = new Thread(()->{
            for (int i = 0; i<10000;i++){
                increase();
            }
        },"这是线程2");
        t1.start();
        t2.start();
        //main线程先阻塞,等t1,t2执行完
        t1.join();
        t2.join();
        System.out.println(count);

    }
}
